package com.hux.vvownerclub.service.vv.impl;

import com.hux.vvownerclub.dbmodel.TUnreadmsg;
import com.hux.vvownerclub.dbmodel.TUser;
import com.hux.vvownerclub.service.vv.UnreadMsgService;

/**
 * Created with IntelliJ IDEA.
 * User: xiang
 * Date: 13-9-10
 * Time: 下午4:19
 */
public class UnreadMsgServiceImpl implements UnreadMsgService {

    //站内留言代码
    private static final String C_INBOX = "0701";

    @Override
    public void addUnreadInboxMsg(int userid) {

        TUser user = TUser.dao.findById(userid);
        if (null != user) {

            TUnreadmsg msg = TUnreadmsg.dao.findFirst("select * form T_UNREADMSG t where t.user = ? and t.type = ?"
                    , userid, C_INBOX);

            if (null == msg) {

                TUnreadmsg nm = new TUnreadmsg();
                nm.set("user", userid);
                nm.set("type", C_INBOX);
                nm.set("num", 0);
                nm.save();
            } else {

                msg.set("num", msg.getInt("num") + 1);
                msg.update();
            }
        }
    }
}
